<?php

// Force le changement du path
chdir(dirname(__FILE__));

// Start an HTTP Session if needed
if(empty($_SESSION)){
        session_start();
        $_SESSION['IP'] = $_SERVER['REMOTE_ADDR'];
} else {
        if ($_SESSION['IP'] != $_SERVER['REMOTE_ADDR']){
                die("Session error, your IP address changed");
        }
}

// Chargement des librairies
require_once(dirname(__FILE__).'/../conf/config.inc.php');
require_once(dirname(__FILE__).'/inc/utils/utils.inc.php');
require_once(dirname(__FILE__).'/../vendor/autoload.php'); //autoload des libs chargées par composer (ne pas enlever)
// Mise à jour du chemin d'inclusion des librairies
set_include_path(get_include_path() . PATH_SEPARATOR . MM_LIB_PATH . PATH_SEPARATOR . MM_INC_PATH);

// Chargement du composant Log4php pour les logs
require_once('Log4php/Logger.php');
Logger::configure(LOG4PHP_PROPERTIES);
$logger = Logger::getRootLogger();

// Initialisation de Twig pour le templating
require_once('Twig/Autoloader.php');
Twig_Autoloader::register();

$loader = new Twig_Loader_Filesystem(MM_TEMPLATE_PATH);
$twig = new Twig_Environment($loader, array(
    'cache' => MM_CACHE_PATH,
        'debug' => MM_DEV_MODE,
        'auto_reload' => MM_DEV_MODE,
));
$twig->addGlobal("session", $_SESSION);


// Connexion à la base de données
$bdd = new PDO('mysql:host='.MM_DB_HOST.';dbname='.MM_DB_NAME.'', ''.MM_DB_USERNAME.'', ''.MM_DB_PASSWORD.'' );
if (!$bdd){
        $logger->fatal("Connection impossible à la base de données");
        die("Database connection error");
}
// Forçage de l'UTF8
$requete = $bdd->prepare("SET NAMES 'utf8'");
$requete->execute();

// Initialisation des variables génériques
$message = $warning = $error = null;
$_SESSION['alerts'] = null;

